package leetcode.editor.cn;

/**
 * @author Administrator
 * @description 仅执行一次字符串交换能否使两个字符串相等
 * @date 2023/3/20 0020
 */
public class Solution1790 {
    public boolean areAlmostEqual(String s1, String s2) {
        int left = 0, right = 0;
        for (int i = 0; i < s1.length(); i++) {
            if (s2.charAt(i) == s1.charAt(i)) continue;
            if (left == 0){
                left = i;
            }else if (right == 0){
                right = i;
            }else {
                return false;
            }
        }
        return s1.charAt(left) == s2.charAt(right) && s1.charAt(right) == s2.charAt(left);
    }
}
